<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('批量入库列表')" />
    <link rel="stylesheet" href="./message.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body class="gray-bg">


     <div class="container-div">
        <div class="row">
            <div hidden id="list" th:text="${session.QuanXian}"></div>
            <div class="btn-group-sm" id="toolbar" role="group">

                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="piliangruku:rukuTest:add">
                    <i class="fa fa-plus"></i> 添加
                </a>


                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="piliangruku:rukuTest:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>

                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="piliangruku:rukuTest:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="piliangruku:rukuTest:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-success" shiro:hasPermission="gouhuoruku:rukuTest:inserts"
                   onclick="submitAll()">
                    <i class="fa fa-plus"></i> 提交
                </a>
                <a class="btn btn-label">
                    <div id="id2toggle" class="fa fa-toggle-off text-info fa-3x" onclick="inStart()">
                        <i class="fa" style="font-size: 45%;vertical-align:45%;">扫码枪录入</i>
                        <textarea id="msg2saoma" oninput="check2input4piliang()" style="height: 0;width: 0;border: 0;padding: unset"></textarea>
                    </div>
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <form name="form" method="post" action="/gouhuoruku/rukuTest/inserts" enctype="multipart/form-data"
                      id="from2Id">
                    <input name="msg" type="text" hidden readonly value="" id="msg">
                </form>
                <table id="bootstrap-table"></table>
            </div>
<!--            <textarea id="msg2saoma" oninput="check2input4piliang()"></textarea>-->
        </div>

<script src="./message.js"></script>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('piliangruku:rukuTest:edit')}]];
        var removeFlag = [[${@permission.hasPermi('piliangruku:rukuTest:remove')}]];
        var paymentMethodDatas = [[${@dict.getType('sys_pay')}]];
        var prefix = ctx + "piliangruku/rukuTest";

        function check2input4piliang() {
            var text = document.getElementById("msg2saoma").value
            console.log(text)
            if (text.search("\n") !== -1){
                onAdd()
            }
        }

        document.onmousemove = mouseMove;
        var oldx = 0,oldy = 0;
        function mouseMove(event) {
            if(document.getElementById("id2toggle").className ==="fa fa-toggle-on text-info fa-3x"){
                var e = event || window.event;
                var scrollx = document.documentElement.scrollLeft || document.body.scrollTop;
                var scrolly= document.documentElement.scrollTop || document.body.scrollTop;
                var x = e.pageX || e.clientX + scrollx;
                var y = e.pageY || e.clientY + scrolly;
                var input2saoma = document.getElementById("msg2saoma");
                const _select_ = document.activeElement
                if ((x !== oldx || y !== oldy)&&_select_ !== input2saoma){
                    document.getElementById("msg2saoma").focus()
                    //console.log(_select_)
                    oldx = x;oldy=y;
                }
            }
        }

        function inStart() {

            var id2toggle = document.getElementById("id2toggle").className
            if (id2toggle === "fa fa-toggle-on text-info fa-3x"){
                document.getElementById("id2toggle").className= "fa fa-toggle-off text-info fa-3x"
                document.getElementById("msg2saoma").blur()
            }else {
                document.getElementById("id2toggle").className= "fa fa-toggle-on text-info fa-3x"
                document.getElementById("msg2saoma").focus()
            }
        }

        function onAdd() {
            var msgStr = document.getElementById("msg2saoma").value
            console.log(msgStr)
            $.ajax({
                type:"POST",
                datatype: "string",
                url: "/piliangruku/rukuTest/inserts",
                data: {"msg": msgStr},
                success: function (result) {

                    console.log(16)
                    if (result.code===0) {

                        $.modal.msgSuccess('成功')
                    }else {
                        $.modal.msgError('录入失败')
                    }
                    console.log("result="+result.code)
                    //console.log(17)
                    //alert("提交成功");
                    //$.modal.msgSuccess('成功')
                    document.getElementById("msg2saoma").value = ""
                    document.getElementById("msg2saoma").focus()
                },
                error : function() {

                    alert("录入失败");

                }
            });
        }
        
        function submitAll() {
            //console.log($('table[id="bootstrap-table"]').children('tbody').children('tr').children()[1].innerHTML)
            var msgv = $('input[name="msg"]')
            var tolength = $('table[id="bootstrap-table"]').children('tbody').children('tr').length
            //console.log(tolength)
            //console.log($('table[id="bootstrap-table"]').children('tbody'))
            for (var i = 0; i < tolength; i++) {
                //console.log(1)
                var f_father = $('table[id="bootstrap-table"]').children('tbody').children('tr')[i]
                //console.log($('table[id="bootstrap-table"]').children('tbody').children('tr')[i].children[1].innerHTML)
                //console.log(f_father.innerHTML.toString())
                //console.log(2)
                var fid = f_father.children[1].innerHTML.toString()
                    //$('input[name="gouhuoDanhao"]').val();
                //console.log(3)
                var fdate = f_father.children[2].innerHTML.toString()
                    //$('input[name="gouhuoDate"]').val()
                //console.log(4)
                var fJingShouRen = f_father.children[3].innerHTML.toString()
                    //$('input[name="gouhuoJingshouren"]').val()
                //console.log(5)
                //const cangku = document.getElementById("gouhuoCangku");

                // console.log(document.getElementById("gouhuoCangku").selectedIndex)
                var fcangkuName = f_father.children[4].innerHTML.toString()
                    //cangku.options[cangku.selectedIndex].value;
                //console.log(6)
                var fShangPinId = f_father.children[5].innerHTML.toString()
                    //$('input[name="goodId"]').val()
                //console.log(7)
                var fleibie = f_father.children[6].innerHTML.toString()
                var fgname = f_father.children[7].innerHTML.toString()
                    //$('input[name="goodName"]').val()
                //console.log(8)
                var fgGuige = f_father.children[8].innerHTML.toString()
                    //$('input[name="goodGuige"]').val()
                //console.log(9)
                var fdan = f_father.children[10].innerHTML.toString()
                var fshu = f_father.children[9].innerHTML.toString()
                    //$('input[name="shuliang"]').val()
                //console.log(10)

                    //$('input[name="dijia"]').val()
                //console.log(11)
                var fzdi = f_father.children[11].innerHTML.toString()
                var ffang,fjin,fbei,fdi;
                console.log(document.getElementById("session2value").innerText.toString())
                if (document.getElementById("session2value").innerText.toString() !== "0"){
                    //console.log(12)
                    fdi = f_father.children[12].innerHTML.toString()
                    ffang = f_father.children[13].innerHTML
                    fjin = f_father.children[14].innerHTML
                    //$('input[name="jiner"]').val()
                    //console.log(13)
                    fbei = f_father.children[15].innerHTML
                    //$('input[name="beizhu"]').val()
                    //console.log(14)
                    $('input[name="msg"]').attr('value',msgv.val()
                        + "@fid:" + fid
                        + ";fdate:" + fdate + ";"
                        + "fJingShouRen:" + fJingShouRen
                        + ";fcangku:" + fcangkuName + ";"
                        + "fShangPinId:" + fShangPinId + ";"
                        + "flei:" + fleibie + ";"
                        + "fgname:" + fgname + ";"
                        + "fgGui:" + fgGuige + ";"
                        + "fshu:" + fshu + ";"
                        + "fdan:" + fdan + ";"
                        + "fdi:" + fdi + ";"
                        + "fzdi:" + fzdi + ";"
                        + "ffang:" + ffang + ";"

                        + "fbei:" + fbei + ";")
                }else {
                    //console.log(12)
                    fdi = f_father.children[11].innerHTML.toString()
                    ffang = f_father.children[12].innerHTML
                    fjin = f_father.children[13].innerHTML
                    //$('input[name="jiner"]').val()
                    //console.log(13)
                    fbei = f_father.children[14].innerHTML
                    //$('input[name="beizhu"]').val()
                    //console.log(14)
                    $('input[name="msg"]').attr('value',msgv.val()
                        + "@fid:" + fid
                        + ";fdate:" + fdate + ";"
                        + "fJingShouRen:" + fJingShouRen
                        + ";fcangku:" + fcangkuName + ";"
                        + "fShangPinId:" + fShangPinId + ";"
                        + "flei:" + fleibie + ";"
                        + "fgname:" + fgname + ";"
                        + "fgGui:" + fgGuige + ";"
                        + "fshu:" + fshu + ";"
                        + "fdan:" + fdan + ";"
                        + "fdi:" + fdi + ";"
                        + "ffang:" + ffang + ";"

                        + "fbei:" + fbei + ";")
                }
                    //$('input[name="zongbudijia"]').val()

            }
            //console.log(15)
            console.log(msgv.val())
            //event.preventDefault();
            $.ajax({
                type:"POST",
                datatype: "string",
                url: "/gouhuoruku/rukuTest/inserts",
                data: {"msg": msgv.val()},
                success: function (result) {
                    console.log(16)
                    if (result.code===0) {
                        alert("提交成功");
                    }else {
                        alert("提交失败")
                    }
                    console.log("result="+result.code)
                    //console.log(17)
                    //alert("提交成功");
                },
                error : function() {

                    alert("提交失败");

                }
            });
            $("#form2Id").find('input[type=hidden]').each(function() {
                $(this).val('');
            });
            $('table[id="bootstrap-table"]').children('tbody').children('tr').empty()
        }

        $(function () {
            if (document.getElementById("session2value").innerText !== "1"){
                $(function() {
                    var options = {
                        url: prefix + "/list",
                        createUrl: prefix + "/add",
                        updateUrl: prefix + "/edit/{id}",
                        removeUrl: prefix + "/remove",
                        exportUrl: prefix + "/export",
                        modalName: "批量入库",
                        columns: [{
                            checkbox: true
                        },
                            {
                                field: 'id',
                                title: '编号',
                                visible: false
                            },
                            {
                                field: 'gouhuoDanhao',
                                title: '单据编号'
                            },
                            {
                                field: 'gouhuoDate',
                                title: '购货日期'
                            },
                            {
                                field: 'gouhuoJingshouren',
                                title: '经手人'
                            },
                            {
                                field: 'gouhuoCangku',
                                title: '仓库'
                            },
                            {
                                field: 'goodId',
                                title: '商品编号'
                            },
                            {
                                field: 'shangpinLeibie',
                                title: '商品类别'
                            },
                            {
                                field: 'goodName',
                                title: '商品名称'
                            },
                            {
                                field: 'goodGuige',
                                title: '商品规格'
                            },
                            {
                                field: 'shuliang',
                                title: '数量'
                            },
                            {
                                field: 'danwei',
                                title: '单位'
                            },
                            {
                                field: 'dijia',
                                title: '底价'
                            },
                            {
                                field: 'paymentMethod',
                                title: '付款方式 ',
                                formatter: function(value, row, index) {
                                    return $.table.selectDictLabel(paymentMethodDatas, value);
                                }
                            },
                            {
                                field: 'jiner',
                                title: '金额'
                            },
                            {
                                field: 'beizhu',
                                title: '备注'
                            },
                            {
                                title: '操作',
                                align: 'center',
                                formatter: function(value, row, index) {
                                    var actions = [];
                                    actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                    actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                                    return actions.join('');
                                }
                            }]
                    };
                    $.table.init(options);
                });
            }else {
                $(function() {
                    var options = {
                        url: prefix + "/list",
                        createUrl: prefix + "/add",
                        updateUrl: prefix + "/edit/{id}",
                        removeUrl: prefix + "/remove",
                        exportUrl: prefix + "/export",
                        modalName: "批量入库",
                        columns: [{
                            checkbox: true
                        },
                            {
                                field: 'id',
                                title: '编号',
                                visible: false
                            },
                            {
                                field: 'gouhuoDanhao',
                                title: '单据编号'
                            },
                            {
                                field: 'gouhuoDate',
                                title: '购货日期'
                            },
                            {
                                field: 'gouhuoJingshouren',
                                title: '经手人'
                            },
                            {
                                field: 'gouhuoCangku',
                                title: '仓库'
                            },
                            {
                                field: 'goodId',
                                title: '商品编号'
                            },
                            {
                                field: 'shangpinLeibie',
                                title: '商品类别'
                            },
                            {
                                field: 'goodName',
                                title: '商品名称'
                            },
                            {
                                field: 'goodGuige',
                                title: '商品规格'
                            },
                            {
                                field: 'shuliang',
                                title: '数量'
                            },
                            {
                                field: 'danwei',
                                title: '单位'
                            },
                            {
                                field: 'zongbudijia',
                                title: '总部底价'
                            },
                            {
                                field: 'dijia',
                                title: '底价'
                            },
                            {
                                field: 'paymentMethod',
                                title: '付款方式 ',
                                formatter: function(value, row, index) {
                                    return $.table.selectDictLabel(paymentMethodDatas, value);
                                }
                            },
                            {
                                field: 'jiner',
                                title: '金额'
                            },
                            {
                                field: 'beizhu',
                                title: '备注'
                            },
                            /*{
                                title: '操作',
                                align: 'center',
                                formatter: function(value, row, index) {
                                    var actions = [];
                                    actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                    actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                                    return actions.join('');
                                }
                            }*/
                            ]
                    };
                    $.table.init(options);
                });
            }
        })

    </script>
</body>
</html>